<template>
  <view>
    <view @click="getZfbPayForm">支付</view>

    <view class="aliform" v-html="aliform"></view>
    <view>{{type}}</view>
  </view>

</template>


<script>
const API = require('../../utils/api/pay.js').default;
const $ = require('../../utils/api.js');
export default {
  name: "index",
  data() {
    return {
      aliform: "",
      type:""
    };
  },
  created() {

    this.IsWeixinOrAlipay()
  },
  methods: {
    IsWeixinOrAlipay() {
      var ua = window.navigator.userAgent.toLowerCase();

      //判断是不是微信
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        this.type = "WeiXIN";
        return
      }
      //判断是不是支付宝
      if (ua.match(/AlipayClient/i) == 'alipayclient') {
        this.type = "Alipay";
        this.getZfbPayForm()
        return;
      }
      //哪个都不是
      this.type = "false";
    },
    getZfbPayForm() {
      const self = this;
      $.ajax({
        url: API.pay,
        data: {
          applicationType: 'xcx',
          payOrderNo: '12312412313',
          payMethod: "aliPay"
        },
        method: 'POST',
        success(res) {
          self.aliform = res.data.message
          self.$nextTick(() => {
            document.forms[0].submit();
          });
        }
      })
    },
  }
}
</script>

<style scoped>

</style>